//
//  TrueBinaryClockViewController.m
//  BinaryClock
//
//  Created by Peter Elst on 7/22/08.
//  Copyright 2008 Peter Elst. All rights reserved.
//

#import "BinaryClockAppDelegate.h"
#import "TrueBinaryClockViewController.h"


@implementation TrueBinaryClockViewController

@synthesize hours;
@synthesize minutes;
@synthesize seconds;
@synthesize clockTimer;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
	if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
	}
	return self;
}

- (void)viewDidLoad {
	[super viewDidLoad];
	[self.view setBackgroundColor: [UIColor blackColor]];
	clockTimer = [NSTimer scheduledTimerWithTimeInterval:1 
						  target:self
						  selector:@selector(getCurrentTime)
						  userInfo:nil 
						  repeats: YES];
	[self getCurrentTime];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	for (UITouch *touch in touches){
		if(touch.tapCount == 2) {
			[(BinaryClockAppDelegate*)[[UIApplication sharedApplication] delegate] toggleView];
		}
	}
}


- (void)getCurrentTime {
	NSDate *now = [NSDate date];
	NSString *timestamp = [now description];
	NSString *currentHour = [timestamp substringWithRange:NSMakeRange(11,2)];
	NSString *currentMinute = [timestamp substringWithRange:NSMakeRange(14,2)];
	NSString *currentSecond = [timestamp substringWithRange:NSMakeRange(17,2)];
	NSLog(@"second: %@",currentSecond);
	[hours setImage: [UIImage imageNamed: [currentHour stringByAppendingString: @"-5.png"]]];
	[minutes setImage: [UIImage imageNamed: [currentMinute stringByAppendingString: @"-6.png"]]];
	[seconds setImage: [UIImage imageNamed: [currentSecond stringByAppendingString: @"-6.png"]]];
}


/*- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return YES;
}*/


- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
	// Release anything that's not essential, such as cached data
}


- (void)dealloc {
	[super dealloc];
}


@end
